package org.eclipse.wtp.puzzled;

import static org.junit.Assert.*;

import org.eclipse.wtp.puzzled.Sudoku;
import org.eclipse.wtp.puzzled.SudokuGenerator;

import org.junit.Test;

public class Test1 {

	@Test
	public void test() {
		boolean test;
		int x, y;//Hello
		int ex=0;
		int ey=0;
		int e1x=0;
		int e1y=0;
		Sudoku s= new Sudoku(0);
		Sudoku s1= new Sudoku(1);
		SudokuGenerator sg = new SudokuGenerator(9);
		if(s.numEmpties()!=15)
			fail("The level was not set correctly.");
		if(s.numHints() !=0)
			fail("The number of hints is not set to zero at start");
		s.hint();
		if(s.numHints() !=1)
			fail("The number of hints did not go up");
		SudokuGenerator s2 = new SudokuGenerator(3);
		
		s2.generate(true);
		if(s.numOrigUserInput()!= 15)
			fail("It is not set to the correct level of difficulty (easy)");
	
		if(s1.numOrigUserInput()!= 25)
			fail("s2 does not have the correct level of difficulty (med)");
		if(s.numUserInput()!= 14)// Hint takes away one
			fail("The number of user inputs is not working correctly"+s.numUserInput());
		if(s.numCorrect() != 0)
			fail("The number correct should be original as no user input"+ s.numCorrect());
		for(x=0;x<9;x++){
			for(y=0; y<9; y++){	
				test=s.cellEmpty(x,y);
				if(test){
					ex=x;
					ey=y;
					if(s.getCell(x, y)!= "")
						fail("The cell is not correctly set"+s.getCell(x,y));
				}
			}
		}
		
		for(x=0;x<9;x++){
			for(y=0; y<9; y++){	
				test=s1.cellEmpty(x,y);
				if(test){
					e1x=x;
					e1y=y;
				}
			}
		}
		s1.showCell(e1x, e1y);
		if(!s1.isCorrect(e1x,e1y))
			fail("Did not show cell");
		for(x=0;x<9;x++){
			for(y=0; y<9; y++){	
				test=s1.cellEmpty(x,y);
				if(test){
					e1x=x;
					e1y=y;
					s1.selectCell(x, y);
					if(s1.getCell(x, y)== Integer.toHexString(1).toUpperCase())
						fail("The cell did not increment."+ s1.getCell(x, y));
					s1.selectCell(x, y);
					if(s1.getCell(x, y)== Integer.toHexString(2).toUpperCase())
						fail("The cell did not increment."+ s1.getCell(x, y));
				}
			}
		}
		
		s.solve();		
		if(s.isCorrect(ex, ey))
			fail("Solve gave the answer to a blank cell as correct to user");
	}
}
